package QueuePackage;

/**
 * @author Lzm
 * @version 1.0
 */
public class QueueTest {
  public static void main(String[] args) {

  }
}
/*队列*/
class Queue{
  private int MaxSize;
  private int front;
  private int rear;
  private int[] arr;
  public Queue(int MaxSize){
    this.MaxSize = MaxSize;
    this.front = 0; //减少数据时移动
    this.rear = 0; //添加数据时移动
    this.arr = new int[MaxSize];
  }
  /*判断队列满*/
  public boolean isFull(){
    return (rear - front) == MaxSize - 1 ;
  }

  /*判断队列空*/
  public boolean isEmpty(){
    return (rear == front);
  }

  /*添加数据*/
  public void add(int number){
    if (isFull()){
      System.out.println("队列已满");
      return;
    }
    /*先移动rear, 后添加数据*/
    arr[rear++] = number;
    return;
  }

  /*取出数据*/
  public int get(){
    if (isEmpty()){
      System.out.println("队列为空");
      return -1;
    }
    /*先移动front, 后取出数据*/
    return arr[front++];
  }

  /*遍历数据*/
  public void list(){
    if (isEmpty()){
      System.out.println("队列为空");
      return ;
    }
    for (int i = 0 ; i < arr.length ; i ++){
      System.out.println(arr[i]);
    }
  }

  /*显示头数据*/
  public int getHead(){
    if (isEmpty()){
      System.out.println("队列为空");
      return -1;
    }
    return arr[front + 1];
  }
}
